package org.imraniqbal.frogger;

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.Vector;

import org.imraniqbal.engine.Game;
import org.imraniqbal.engine.GameController;
import org.imraniqbal.engine.GamePanel;
import org.imraniqbal.engine.Mappable;

public class FroggerPanel extends GamePanel<FroggerGame> {

	private static final long serialVersionUID = 3475063687347465055L;
	/**
	 * @author Colin
	 */
	public FroggerPanel(Game g) {
		super(g);
		this.setBgColor(new Color(200,200,200));
		this.setMazeColor(new Color(0,0,0));
	}
	/**
	 * @author imran
	 */
	@Override
	public void newGame() {
		FroggerGame fg = new FroggerGame();
		setGame(fg);
		removeGc(getGc());
		setGc(new GameController<FroggerGame>(fg, this));
		
		repaint();
	}
	/**
	 * @author imran
	 */
	@Override
	protected void DrawMappable(Vector<Mappable> mappable, Graphics2D g2d) {
		for( Mappable m : mappable){
			int y = m.getY();
			int x = m.getX();
			if( m instanceof Frogger){
				switch(((Frogger)m).getDirection()){
				case DOWN:
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/frogger/frog3.png"));
					return;
				case LEFT:
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/frogger/frog4.png"));
					return;
				case RIGHT:
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/frogger/frog2.png"));
					return;
				case UP:
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/frogger/frog1.png"));
					return;
				}
			}
			else if( m instanceof Car){
				DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/frogger/car" + ((Car)m).getID() + ".png"));
			}
			else if( m instanceof Flower){
				DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/frogger/Flower.png"));
			}
			else{
				DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/frogger/lillypad.png"));
			}
		}

	}

}
